﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Babel.Parser;
using Babel.ParserGenerator;

namespace dragonangel.phpProject.Language.DSL
{
    public class CodeFunction : CodeMember
    {
        public CodeFunction(LexLocation begin, LexLocation end) : base(GlyphVisibility.Public, begin, end) { }

        public CodeFunction(string name, GlyphVisibility visibility, bool isAbstract, LexLocation begin, LexLocation end)
            : this(begin, end)
        {
            this.name = name;
            this.isAbstract = isAbstract;
        }

        public CodeFunction(string name, bool isAbstract, LexLocation begin, LexLocation end)
            : this(name, GlyphVisibility.Public, isAbstract, begin, end)
        {
        }


        public CodeFunction(string name, LexLocation begin, LexLocation end)
            : this(name, false, begin, end)
        {
        }

        protected string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        protected bool isAbstract;
        public bool IsAbstract
        {
            get { return isAbstract; }
            set { isAbstract = value; }
        }


        protected CodeStatementCollection statements = new CodeStatementCollection();
        public CodeStatementCollection Statements
        {
            get { return statements; }
            set { statements = value; }
        }

        public override CodeExpression GetExpression(int line, int col)
        {
            foreach (CodeStatement exp in statements)
            {
                CodeExpression result = exp.GetExpression(line, col);
                if (result != null)
                    return result;
            }
            return base.GetExpression(line, col);
        }

        public void AddParemeter(CodeVariable variable)
        {
            availableVariablesInScope.Add(variable);
        }
    }
}
